/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.agi.util.sound;

import br.com.agi.util.geradordados.ManipuladorByte;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.TargetDataLine;

/**
 *
 * @author Renato
 */
public class MicrofoneRealTime implements ManipuladorByte  {
    private final InputMixer buscador;
    private final TargetDataLine inputLine;
    
    public MicrofoneRealTime(InputConfig config) throws LineUnavailableException{
        buf=new byte[(int)config.getSampleRate()];
        buscador=new InputMixer(config);
        inputLine= buscador.getLine();
    }
    
    @Override
    public void open() throws LineUnavailableException{
        inputLine.open();
        inputLine.start();
    }
    
    @Override
    public void close(){
        inputLine.stop();
        inputLine.close();        
    }
    
    private byte[] buf;
    @Override
    public void setBuf(byte[] buf) {
        this.buf=buf;
    }

    @Override
    public void manipula(int off, int len) {
        inputLine.read(buf, off, len);        
    }

    @Override
    public byte[] getBuf() {
        return buf;
    }

   
    
}
